package com.example.flowermall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.flowermall.entity.Product;
import com.example.flowermall.entity.ProductImg;
import com.example.flowermall.entity.Tag;
import com.example.flowermall.mapper.ProductImgMapper;
import com.example.flowermall.mapper.ProductMapper;
import com.example.flowermall.mapper.TagMapper;
import com.example.flowermall.service.IProductImgService;
import com.example.flowermall.service.IProductService;
import com.example.flowermall.service.ITagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-08-23
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {
    @Autowired
    TagMapper tagMapper;
    @Autowired
    ProductMapper productMapper;

    @Autowired
    IProductService productService;

    @Autowired
    IProductImgService productImgService;
    @Override
    public List<Tag> getList() {
        LambdaQueryWrapper<Tag> queryWrapper=new LambdaQueryWrapper<>();
        List<Tag> tags = tagMapper.selectList(queryWrapper);
        for(int i=0;i<tags.size();i++){
            List<Product> products = productService.selectByTagId(tags.get(i).getTagId());
            /*for(int k=0;k<products.size();k++){
                ProductImg productImg = productImgService.getByProductId(products.get(i).getProductId());
                if(productImg!=null){
                    products.get(i).setProductUrl(productImg.getImgUrl());
                }
            }*/
            tags.get(i).setProducts(products);
        }
        return tags;
    }
}
